package com.sunagy.demand.backend.controller;

import com.sunagy.demand.backend.VO.ResultVO;
import com.sunagy.demand.backend.VO.response.CustomerProductResponseVO;
import com.sunagy.demand.backend.service.CustomerProductService;
import com.sunagy.demand.backend.utils.ResultVOUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * desc：用户需求进程接口
 * author：三餘無夢生
 * date：2018/4/11
 * time：下午4:10
 */
@Slf4j
@RestController
@RequestMapping("/customerProduct")
@Api(value = "管理端用户的产品", description = "用户选择的产品")
public class CustomerProductController {

    @Autowired
    private CustomerProductService customerProductService;

    @ApiOperation(value = "查询用户选择的产品", notes = "根据用户id信息查询用户自己选择的产品")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public ResultVO<List<CustomerProductResponseVO>> getList(@PathVariable("id") Integer customerId) {
        List<CustomerProductResponseVO> customerProductResponseVOList = customerProductService.getProductListByUserId(customerId);
        return ResultVOUtil.success(customerProductResponseVOList);
    }

    @ApiOperation(value = "选择产品给用户", notes = "选择某个给用户产品")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "java.lang.Integer", name = "customerId", value = "customerId", required = false, paramType = "path"),
            @ApiImplicitParam(dataType = "java.lang.Integer", name = "productId", value = "productId", required = false, paramType = "body")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/{id}",method = RequestMethod.POST)
    public ResultVO<CustomerProductResponseVO> pickProduct(@PathVariable("id") Integer customerId,@RequestBody Integer productId) {
        CustomerProductResponseVO customerProductResponseVO = customerProductService.pickProduct(customerId,productId);
        return ResultVOUtil.success(customerProductResponseVO);
    }

    @ApiOperation(value = "批量选择产品给用户", notes = "选择某些产品给用户")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/multi/{id}",method = RequestMethod.POST)
    public ResultVO<List<CustomerProductResponseVO>> pickMutiProduct(@PathVariable("id") Integer customerId,@RequestBody Integer[] ids) {
        List<CustomerProductResponseVO> customerProductResponseVOList = customerProductService.pickProducts(customerId,ids);
        return ResultVOUtil.success(customerProductResponseVOList);
    }

}
